import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import vueDevTools from 'vite-plugin-vue-devtools'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import path from 'path'
import VueSetupExtend from 'vite-plugin-vue-setup-extend'
// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    Components(),
    AutoImport({
      imports: ['vue', 'vue-router', 'pinia'],
      dts: false,
    }),
    VueSetupExtend(),
    createSvgIconsPlugin({
      iconDirs: [path.resolve(process.cwd(), 'src/assets/svg')],
      symbolId: 'icon-[name]', // 支持目录层级：'icon-[dir]-[name]'
      inject: 'body-last', // DOM插入位置
      customDomId: '__svg_icons', // 自定义容器ID
    }),
    // vueDevTools(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
    extensions: ['.js', '.mjs'],
  },
  server: {
    port: 8024,
    host: true,
    open: true,
    proxy: {
      '/dev-api': {
        //线上地址
        target: 'http://111.202.231.146:8016/jcy/prod-api',
        //本地
        // target: 'http://192.168.11.248:8081',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/dev-api/, ''),
      },
      '/jcy/prod-api': {
        //线上地址
        target: 'http://111.202.231.146:8016/jcy/prod-api',
        changeOrigin: true,
      },
    },
  },
})
